package com.ruoyi.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.app.domain.AppBanners;
import com.ruoyi.app.mapper.AppBannersMapper;
import com.ruoyi.app.service.IAppBannersService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * bannerService业务层处理
 *
 * @author jiang
 * @date 2024-11-12
 */
@Service
public class AppBannersServiceImpl extends ServiceImpl<AppBannersMapper, AppBanners> implements IAppBannersService {
    @Autowired
    private AppBannersMapper appBannersMapper;

    /**
     * 查询banner
     *
     * @param id banner主键
     * @return banner
     */
    @Override
    public AppBanners selectAppBannersById(Long id) {
        return appBannersMapper.selectAppBannersById(id);
    }

    /**
     * 查询banner列表
     *
     * @param appBanners banner
     * @return banner
     */
    @Override
    public List<AppBanners> selectAppBannersList(AppBanners appBanners) {
        return appBannersMapper.selectAppBannersList(appBanners);
    }

    /**
     * 新增banner
     *
     * @param appBanners banner
     * @return 结果
     */
    @Override
    public int insertAppBanners(AppBanners appBanners) {
        appBanners.setCreateTime(DateUtils.getNowDate());
        return appBannersMapper.insertAppBanners(appBanners);
    }

    /**
     * 修改banner
     *
     * @param appBanners banner
     * @return 结果
     */
    @Override
    public int updateAppBanners(AppBanners appBanners) {
        appBanners.setUpdateTime(DateUtils.getNowDate());
        return appBannersMapper.updateAppBanners(appBanners);
    }

    /**
     * 批量删除banner
     *
     * @param ids 需要删除的banner主键
     * @return 结果
     */
    @Override
    public int deleteAppBannersByIds(Long[] ids) {
        return appBannersMapper.deleteAppBannersByIds(ids);
    }

    /**
     * 删除banner信息
     *
     * @param id banner主键
     * @return 结果
     */
    @Override
    public int deleteAppBannersById(Long id) {
        return appBannersMapper.deleteAppBannersById(id);
    }

    @Override
    public List<AppBanners> getFirstList() {
        QueryWrapper<AppBanners> wrapper = new QueryWrapper<>();
        wrapper.eq("banners_type", 1).orderByAsc("sort_order");
        return baseMapper.selectList(wrapper);
    }
}

